package experiment12;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class No_2 extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        HBox text_box=new HBox();
        HBox control_box=new HBox();
        BorderPane pane=new BorderPane();

        text_box.getChildren().add(new Label("text:"));
        TextField textField=new TextField("Javafx");
        textField.setAlignment(Pos.BOTTOM_RIGHT);
        text_box.getChildren().add(textField);

        ToggleGroup toggleGroup=new ToggleGroup();
        RadioButton left=new RadioButton("Left");
        RadioButton center=new RadioButton("Center");
        RadioButton right=new RadioButton("Right");
        left.setToggleGroup(toggleGroup);
        center.setToggleGroup(toggleGroup);
        right.setToggleGroup(toggleGroup);
        TextField size=new TextField(String.valueOf(textField.getPrefColumnCount()));
        control_box.getChildren().addAll(left,center,right,new Label("Column size:"),size);

        pane.setCenter(text_box);
        pane.setBottom(control_box);

        right.setOnAction(event -> {
            textField.setAlignment(Pos.BASELINE_RIGHT);
        });
        left.setOnAction(event -> {
            textField.setAlignment(Pos.BASELINE_LEFT);
        });
        center.setOnAction(event -> {
            textField.setAlignment(Pos.BASELINE_CENTER);
        });
        size.setOnAction(event -> {
            textField.setPrefColumnCount(Integer.parseInt(size.getText()));
        });

        primaryStage.setTitle("change text");
        primaryStage.setScene(new Scene(pane));
        primaryStage.show();
    }
}
